package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.DeviceWhiteCall;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.utils.UnicodeUtil;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;

public class SetSingleWhiterListNumberSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        DeviceWhiteCall deviceWhiteCall = (DeviceWhiteCall)mqMessage.getObject();
        String imei = deviceWhiteCall.getImei();
        String commandNumber = deviceWhiteCall.getCommandNumber();
        String name ="";
        if(!StringUtils.isBlank(deviceWhiteCall.getName())){
             name = UnicodeUtil.gbEncoding(deviceWhiteCall.getName());
        }
        String phone = deviceWhiteCall.getPhone();
         Integer sequence = deviceWhiteCall.getSequence();
        String whiteCallContent = ",".concat(String.valueOf(sequence)).concat(",").concat(phone).concat(",1,0,").concat(name).concat(",1");
        String content = "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",").concat(mqMessage.getType()).concat(",").concat(commandNumber)
                .concat(whiteCallContent).concat("#");
        Command command = new Command();
        command.setImei(imei);
        command.setCommandNumber(commandNumber);
        command.setCmd(mqMessage.getType());
        command.setContent(content);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setSequence(deviceWhiteCall.getSequence());
        return command;
    }
}
